/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.geftu.model;

import java.beans.PropertyChangeSupport;

import javax.persistence.Basic;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Transient;

import br.com.geftu.util.SwingColumn;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.swing.table.DefaultTableCellRenderer;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotEmpty;

/**
 *
 * @author Nei
 */
@Entity
@Table(name = "tb_anexo", catalog = "bddefeitos", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Anexo.findAll", query = "SELECT t FROM Anexo t"),
    @NamedQuery(name = "Anexo.findByAnexo", query = "SELECT t FROM Anexo t WHERE t.caminho = :caminho"),
    @NamedQuery(name = "Anexo.findByIdanx", query = "SELECT t FROM Anexo t WHERE t.idanx = :idanx"),
    @NamedQuery(name = "Anexo.findByRelato", query = "SELECT t FROM Anexo t WHERE t.relato = :relato")
})

public class Anexo implements Serializable {

    /**
     * @return the serialVersionUID
     */
    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    /**
     * @param aSerialVersionUID the serialVersionUID to set
     */
    public static void setSerialVersionUID(long aSerialVersionUID) {
        serialVersionUID = aSerialVersionUID;
    }

    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "idanx", sequenceName = "anexo_seq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idanx")
    @Basic(optional = false)
    @SwingColumn(description = "The Id", renderer = DefaultTableCellRenderer.class, colorOfBackgound = "")
    private Integer idanx;
    @NotNull(message = "O campo não pode ser nulo")
    @NotEmpty(message = "O campo não pode estar em branco")
    @Size(min = 4, max = 50, message = "O campo dever possuir entre 4 e 50 caracteres")
    @SwingColumn(description = "Anexo", renderer = DefaultTableCellRenderer.class, colorOfBackgound = "")
    @Column(unique = true)
    private String caminho;
    @Basic(optional = false)
    @JoinColumn(name = "relato", referencedColumnName = "idrel", nullable = false)
    @ManyToOne(optional = false)
    private Relato relato;

    public Anexo() {

    }

    public Anexo(int id, String caminho) {
        this.idanx = idanx;
        this.caminho = caminho;
    }

    public Anexo(Relato relato, String caminho) {
        this.relato = relato;
        this.caminho = caminho;
    }

    /**
     * @param relato
     */
    public void setRelatos(Relato relato) {
        this.setRelato(relato);
    }

    public Relato getRelato() {
        return relato;
    }

    /**
     * @param relato the relato to set
     */
    public void setRelato(Relato relato) {
        this.relato = relato;
    }

    /**
     * @return the changeSupport
     */
    public PropertyChangeSupport getChangeSupport() {
        return changeSupport;
    }

    /**
     * @param changeSupport the changeSupport to set
     */
    public void setChangeSupport(PropertyChangeSupport changeSupport) {
        this.changeSupport = changeSupport;
    }

    /**
     * @return the idanx
     */
    public Integer getIdanx() {
        return idanx;
    }

    /**
     * @param idanx the idanx to set
     */
    public void setIdanx(Integer idanx) {
        this.idanx = idanx;
    }

    /**
     * @return the caminho
     */
    public String getCaminho() {
        return caminho;
    }

    /**
     * @param caminho the caminho to set
     */
    public void setCaminho(String caminho) {
        this.caminho = caminho;
    }
}
